/**
 * @file skoll.tools.js
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: skoll.tools.js 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/skins/Skoll/js/skoll.tools.js $
 */

/**
 * Skoll skin tools collection.
 * @{
 */
Skoll.tools._logPrefix = "SkollLog: ";
Skoll.tools.log = function(obj) {
	if (typeof Skoll.config.debug == "undefined" || Skoll.config.debug) {
		if (typeof obj == "string") {
			console.log(Skoll.tools._logPrefix + obj);
		} else {
			console.log(Skoll.tools._logPrefix);
			console.log(obj);
		}
	}
}
Skoll.tools.extraUrlParams = function() {
	var url = window.location.href;
	var out = "";

	var pattern = /^(.*)([\&\?])(nocache|resetcache)([^\&\?]*)(.*)$/;
	if (url.match(pattern)) {
		out += url.replace(pattern, '&$3');
	}
	var pattern = /^(.*)([\&\?])(nolang)([^\&\?]*)(.*)$/;
	if (url.match(pattern)) {
		out += url.replace(pattern, '&$3');
	}
	var pattern = /^(.*)([\&\?])(wclang)([^\&\?]*)(.*)$/;
	if (url.match(pattern)) {
		out += url.replace(pattern, '&$3$4');
	}

	return out;
};
Skoll.tools.preventDefault = function(event) {
	if (typeof event == "undefined" && typeof window.event != "undefined") {
		event = window.event;
	}
	if (typeof event != "undefined") {
		if (event.preventDefault) {
			event.preventDefault();
		} else {
			// Bloody IE
			event.returnValue = false;
		}
		if (event.stopPropagation) {
			event.stopPropagation();
		}
	}
};
Skoll.tools.reload = function() {
	Skoll.tools.preventDefault();
	window.location.reload();
};
Skoll.tools.reloadHome = function() {
	Skoll.tools.preventDefault();
	window.location.href = "?group=" + GROUP_ID;
};
Skoll.tools.switchGroup = function(id) {
	Skoll.tools.preventDefault();
	window.location.href = "?group=" + id;
};
/** @} */

String.prototype.basename = function() {
	return this.replace(/(^.*)\/([^\/\\]*)$/, '$2');
};
String.prototype.dirname = function() {
	return this.replace(/(^.*)\/([^\/\\]*)$/, '$1');
};
